<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" />
    <title>奖惩审核</title>
    <link rel="stylesheet" href="{{asset('/addons/jquery-weui-build/css/weui.min.css')}}">
    <link rel="stylesheet" href="{{asset('/addons/jquery-weui-build/css/jquery-weui.css')}}">
    <link rel="stylesheet" href="{{asset('/css/system/iconfont.css')}}">
    <link rel="stylesheet" href="{{asset('/css/system/common.css')}}">
    <link rel="stylesheet" href="{{asset('/css/system/rewards-punish.css')}}">
    @include('sysadmin.head')
</head>
<body ontouchstart>
<div class="mian-container">
    <div class="rewards-punish">
        {{--<div class="weui-cells">
          <a class="weui-cell weui-cell_access" href="{{url('/sysadmin/reward/reward-punish-set')}}">
            <div class="weui-cell__bd">
              <p>奖惩设置：</p>
            </div>
            <div class="weui-cell__ft">
            </div>
          </a>        
        </div>--}}
        <div class="weui-tab">
          <div class="weui-navbar">
            <a class="weui-navbar__item weui-bar__item--on" href="#tab1">
              <i class="icon icon-a iconfont icon-xiaolian15"></i>
              <p>奖励</p>
            </a>
            <a class="weui-navbar__item" href="#tab2">
              <i class="icon icon-a iconfont icon-kulian"></i>
              <p>惩罚</p>
            </a>
          </div>
          <div class="weui-tab__bd">
            <div id="tab1" class="weui-tab__bd-item weui-tab__bd-item--active">
                @foreach($reward as $p)
                    @if($p->is_effective == 0)
                        <div class="rewards-section">
                            <div class="header-sec">
                                <h3>{{$p->created_at->format('Ymd')}}奖励</h3>
                                <p class="icon-level">{{$p->grade}}</p>
                            </div>
                            <div class="middle-sec">
                                <p class="text-left">{{getUserName($p->from_user_id)}}对{{getUserName($p->to_user_id)}}</p>
                                <p class="text-middle">{{$p->reason}}</p>
                                <div>
                                    <a class="link-a change-level" href="javascript:void(0);" value="{{$p->grade}}" data-values="{{$p->score}}">修改等级</a>
                                    <input type="hidden" class="level-input">
                                    <a class="link-a pass-link" data-id="{{$p->id}}" href="javascript:void(0);">通过</a>
                                    <a class="link-a refuse-link" data-id="{{$p->id}}" href="javascript:void(0);">拒绝</a>
                                </div>
                                <p class="text-list">审批流程</p>
                                <div class="hidden-list weui-cells">
                                    @foreach(unserialize($p->detail) as $pd)
                                        <div class="weui-cell">
                                            <i class="weui-icon-success"></i>
                                            <div class="weui-cell__bd">
                                                <p>{{$pd}}</p>
                                            </div>
                                        </div>
                                    @endforeach
                                </div>
                            </div>
                        </div>
                    @endif
                @endforeach
                @foreach($reward as $p)
                    @if($p->is_effective != 0)
                        <div class="rewards-section">
                        <div class="header-sec">
                            <h3>{{$p->created_at->format('Ymd')}}奖励</h3>
                            <p class="icon-level">{{$p->grade}}</p>
                        </div>
                        <div class="middle-sec">
                            <p class="text-left">{{getUserName($p->from_user_id)}}对{{getUserName($p->to_user_id)}}</p>
                            <p class="text-middle">{{$p->reason}}</p>
                            <p class="text-right">@if($p->is_effective == 1)已通过@elseif($p->is_effective == 2)未通过@else审核中@endif</p>
                            <p class="text-list">审批流程</p>
                            <div class="hidden-list weui-cells">
                                @foreach(unserialize($p->detail) as $pd)
                                    <div class="weui-cell">
                                        <i class="weui-icon-success"></i>
                                        <div class="weui-cell__bd">
                                            <p>{{$pd}}</p>
                                        </div>
                                    </div>
                                @endforeach
                            </div>
                        </div>
                    </div>
                    @endif
                @endforeach
            </div>
            <div id="tab2" class="weui-tab__bd-item">
                @foreach($punish as $p)
                    @if($p->is_effective == 0)
                        <div class="rewards-section">
                            <div class="header-sec">
                                <h3>{{$p->created_at->format('Ymd')}}惩罚</h3>
                                <p class="icon-level">{{$p->grade}}</p>
                            </div>
                            <div class="middle-sec">
                                <p class="text-left">{{getUserName($p->from_user_id)}}对{{getUserName($p->to_user_id)}}</p>
                                <p class="text-middle">{{$p->reason}}</p>
                                <div>
                                    <a class="link-a change-level" href="javascript:void(0);" value="{{$p->grade}}" data-values="{{$p->score}}">修改等级</a>
                                    <input type="hidden" class="level-input">
                                    <a class="link-a pass-link" data-id="{{$p->id}}" href="javascript:void(0);">通过</a>
                                    <a class="link-a refuse-link" data-id="{{$p->id}}" href="javascript:void(0);">拒绝</a>
                                </div>
                                <p class="text-list">审批流程</p>
                                <div class="hidden-list weui-cells">
                                    @foreach(unserialize($p->detail) as $pd)
                                        <div class="weui-cell">
                                            <i class="weui-icon-success"></i>
                                            <div class="weui-cell__bd">
                                                <p>{{$pd}}</p>
                                            </div>
                                        </div>
                                    @endforeach
                                </div>
                            </div>
                        </div>
                    @endif
                @endforeach
                @foreach($punish as $p)
                    @if($p->is_effective != 0)
                        <div class="rewards-section">
                            <div class="header-sec">
                                <h3>{{$p->created_at->format('Ymd')}}惩罚</h3>
                                <p class="icon-level">{{$p->grade}}</p>
                            </div>
                            <div class="middle-sec">
                                <p class="text-left">{{getUserName($p->from_user_id)}}对{{getUserName($p->to_user_id)}}</p>
                                <p class="text-middle">{{$p->reason}}</p>
                                <p class="text-right">@if($p->is_effective == 1)已通过@elseif($p->is_effective == 2)未通过@else审核中@endif</p>
                                <p class="text-list">审批流程</p>
                                <div class="hidden-list weui-cells">
                                    @foreach(unserialize($p->detail) as $pd)
                                        <div class="weui-cell">
                                            <i class="weui-icon-success"></i>
                                            <div class="weui-cell__bd">
                                                <p>{{$pd}}</p>
                                            </div>
                                        </div>
                                    @endforeach
                                </div>
                            </div>
                        </div>
                    @endif
                @endforeach
            </div>
             {!! csrf_field() !!}
          </div>
        </div>
    </div>
    <!-- 隐藏考核按钮部分-->
    <div class="reful-tabbar">
        <a href="{{url('/user/performance/perf')}}" class="tabbar-item">
            <p style="line-height: 65px;" class="tabbar-label">返回个人用户界面</p>
        </a>
    </div>
</div>
<script src="{{asset('/kaohe/js/jquery-2.1.4.min.js')}}"></script>
<script src="{{asset('/addons/jquery-weui-build/js/fastclick.js')}}"></script>
<script>
    $(function() {
        document.documentElement.style.fontSize = document.documentElement.clientWidth / 7.5 + 'px';
        FastClick.attach(document.body);
    });
</script>
<script src="{{asset('/addons/jquery-weui-build/js/jquery-weui.min.js')}}"></script>
<script>
    $(document).ready(function () {
        $('.text-list').click(function(){
            $(this).toggleClass('text-cha');
            $(this).next('.hidden-list').toggle();
        })
        $('.kaohe-item').click(function(){
            $('.show-hidden').toggle();
        });
        $('.admin-item').click(function(){
            $('.front-show-hidden').toggle();
        });
        /*$('.change-level').click(function(){
            var that = this
            $(that).picker({
              title: "选择等级",
              cols: [
                {
                  textAlign: 'center',
                  values: [ '低级','中级', '高级']
                }
              ],
              onClose: function(data){
                  //ajax，后台
                console.log( $(that).parent().parent().parent().find('.icon-level').text());
                 
                $(that).parent().parent().parent().find('.icon-level').text(data.value[0]);
              }
            });  
        });*/


        var rearray = {!! $reward_set !!};
        $(".change-level").select({
            title: "选择等级",
            items: rearray
        });

        var puarray = {!! $punish_set !!};
        $(".change-p-level").select({
            title: "选择等级",
            items: puarray
        });

        $('.refuse-link').click(function(){
            var rid = $(this).attr('data-id');
            var grade = $(this).parent().find('a.change-level').val();
            var level = $(this).parent().find('a.change-level').attr('data-values');
//            alert(grade);
//            alert(level);
            var token = $('input[name=_token]').val();
            $.ajax({
                'url': '/sysadmin/reward/verify-reward?agree=2&_token='+token+'&rid='+rid,
                'type': 'POST',
                'data': '&grade='+grade+'&level='+level,
                error: function (request) {
                    $.toast('网络错误',"text");
                },
                success: function (data) {
                    if (data.status == 'success') {
                        $.toast("操作成功");
                        setTimeout(function(){ window.location.reload(); }, 1000);
                    } else {
                        $.toast(data.msg,"text");
                    }
                },
            });
        });

        $('.pass-link').click(function(){
            var rid = $(this).attr('data-id');
            var grade = $(this).parent().find('a.change-level').attr('value');
            var level = $(this).parent().find('a.change-level').attr('data-values');
            //alert(grade);
            //alert(level);
            var token = $('input[name=_token]').val();
            $.ajax({
                'url': '/sysadmin/reward/verify-reward?agree=1&_token='+token+'&rid='+rid,
                'type': 'POST',
                'data': '&grade='+grade+'&level='+level,
                error: function (request) {
                    $.toast('网络错误',"text");
                },
                success: function (data) {
                    if (data.status == 'success') {
                        $.toast("操作成功");
                        setTimeout(function(){ window.location.reload(); }, 1000);
                    } else {
                        $.toast(data.msg,"text");
                    }
                },
            });
        });
    })
</script>
</body>
</html>